home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / test / navigation.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  2.3 KB  |  71 lines

  1. //
  2. // "$Id: navigation.cxx,v 1.5 1999/01/07 19:17:58 mike Exp $"
  3. //
  4. // Navigation test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Silly test of navigation keys. This is not a recommended method of
  7. // laying out your panels!
  8. //
  9. // Copyright 1998-1999 by Bill Spitzak and others.
  10. //
  11. // This library is free software; you can redistribute it and/or
  12. // modify it under the terms of the GNU Library General Public
  13. // License as published by the Free Software Foundation; either
  14. // version 2 of the License, or (at your option) any later version.
  15. //
  16. // This library is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. // Library General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU Library General Public
  22. // License along with this library; if not, write to the Free Software
  23. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  24. // USA.
  25. //
  26. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  27. //
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <FL/Fl.H>
  32. #include <FL/Fl_Window.H>
  33. #include <FL/Fl_Input.H>
  34.  
  35. #define WIDTH 600
  36. #define HEIGHT 300
  37. #define GRID 25
  38.  
  39. int main(int argc, char **argv) {
  40.   if (argc > 1) srand(atoi(argv[1]));
  41.   Fl_Window window(WIDTH,HEIGHT,argv[0]);
  42.   window.end(); // don't auto-add children
  43.   for (int i = 0; i<10000; i++) {
  44.     // make up a random size of widget:
  45.     int x = rand()%(WIDTH/GRID+1) * GRID;
  46.     int y = rand()%(HEIGHT/GRID+1) * GRID;
  47.     int w = rand()%(WIDTH/GRID+1) * GRID;
  48.     if (w < x) {w = x-w; x-=w;} else {w = w-x;}
  49.     int h = rand()%(HEIGHT/GRID+1) * GRID;
  50.     if (h < y) {h = y-h; y-=h;} else {h = h-y;}
  51.     if (w < GRID || h < GRID || w < h) continue;
  52.     // find where to insert it and see if it intersects something:
  53.     Fl_Widget *j = 0;
  54.     int n; for (n=0; n < window.children(); n++) {
  55.       Fl_Widget *o = window.child(n);
  56.       if (x<o->x()+o->w() && x+w>o->x() &&
  57.       y<o->y()+o->h() && y+h>o->y()) break;
  58.       if (!j && (y < o->y() || y == o->y() && x < o->x())) j = o;
  59.     }
  60.     // skip if intersection:
  61.     if (n < window.children()) continue;
  62.     window.insert(*(new Fl_Input(x,y,w,h)),j);
  63.   }
  64.   window.show();
  65.   return Fl::run();
  66. }
  67.  
  68. //
  69. // End of "$Id: navigation.cxx,v 1.5 1999/01/07 19:17:58 mike Exp $".
  70. //
  71.